from CvPythonExtensions import *
from WriterUtils import *

import CvScreenEnums
import CvUtil
import CvConfigParser
import CvPath
import os
import os.path
import Popup as PyPopup
import shutil 
import PromotionInfoWriter
import CivicInfoWriter
import BuildingInfoWriter
import SpecialBuildingInfoWriter
import CivilizationInfoWriter
import HandicapInfoWriter
import BuildInfoWriter
import RouteInfoWriter
import ImprovementInfoWriter
import BonusInfoWriter
import ProcessInfoWriter
import ProjectInfoWriter
import ReligionInfoWriter
import UnitInfoWriter

# globals
gc = CyGlobalContext()
ArtFileMgr = CyArtFileMgr()
localText = CyTranslator()

# Change this to change the location where the resulting CIV4TechInfos.xml file 
# will be saved. So if the default value is left to "Test" then the 
# CIV4TechInfos.xml file would be written in a directory called "Test" inside 
# of the Tech Tree Editor mod folder.
# Default value is Test
g_strSaveDirectoryLocation = "Test"

# Change the value to false if the assets directory structure shouldn't be 
# created at the directory specified by the "Save Directory Location".
# Default value is True
g_bCreateAssetHierarchy = True

# Change the value to false if the changes made shouldn't be saved into the 
# assets directory for the tech editor. Changing it to false will require 
# manual copying of the saved files from the directory specified in the 
# "Save Directory Location" configurable option to the editor's asset directory 
# when wanting to edit existing mod files.
# Default value is True
g_bSaveChangesInEditorAssetsDirectory = True

def loadConfigurationValues():
	global g_strSaveDirectoryLocation
	global g_bCreateAssetHierarchy
	global g_bSaveChangesInEditorAssetsDirectory
	
	config = CvConfigParser.CvConfigParser("ViSa_v3.ini")

	if(config != None):
		g_strSaveDirectoryLocation = config.get("Tech Tree Editor", "Save Directory Location", "Test")
		g_bCreateAssetHierarchy = config.getboolean("Tech Tree Editor", "Create Asset Hierarchy", True)
		g_bSaveChangesInEditorAssetsDirectory = config.getboolean("Tech Tree Editor", "Save Changes In Editor Assets Directory", True)

		if(len(g_strSaveDirectoryLocation) == 0):
			g_strSaveDirectoryLocation = "Test"
			
class TechInfoWriter:
		
	def __init__(self):
		loadConfigurationValues()
	

	def isDomainExtraMovesDefined(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)
	
		for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
			if(objTechInfo.getDomainExtraMoves(iI) != 0):
				return true;
				
		return false

	def isCommerceFlexibleDefined(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)

		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objTechInfo.isCommerceFlexible(iI)):
				return true

		return false
				
	def isTerrainTradeDefined(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)

		for iI in range(gc.getNumTerrainInfos()):
			if(objTechInfo.isTerrainTrade(iI)):
				return true
				
		return false

	def isFlavorsDefined(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)

		for iI in range(gc.getNumFlavorTypes()):
			if(objTechInfo.getFlavorValue(iI) != 0):
				return true	

		return false							

	def isPrereqOrTechsDefined(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)

		for iI in range (gc.getDefineINT("NUM_OR_TECH_PREREQS")):
			if(objTechInfo.getPrereqOrTechs(iI) != TechTypes.NO_TECH):
				return true			
		return false

	def isPrereqAndTechsDefined(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)

		for iI in range (gc.getDefineINT("NUM_AND_TECH_PREREQS")):
			if(objTechInfo.getPrereqAndTechs(iI) != TechTypes.NO_TECH):
				return true			
		return false
	
	def printTech(self, iTech):
		objTechInfo = gc.getTechInfo(iTech)

		szText = ""
		
		szText = appendString(szText,"		<TechInfo>")
		szText = appendString(szText,"			<Type>%s</Type>" %(objTechInfo.getType()))
		szText = appendString(szText,"			<Description>%s</Description>" %(objTechInfo.getTextKey()))
		szText = appendString(szText,"			<Civilopedia>%s</Civilopedia>" %(objTechInfo.getCivilopediaKey()))

		if(len(objTechInfo.getHelpKey()) > 0):
			szText = appendString(szText,"			<Help>%s</Help>" %(objTechInfo.getHelpKey()))
		else:
			szText = appendString(szText,"			<Help/>")
		
		szText = appendString(szText,"			<Strategy>%s</Strategy>" %(objTechInfo.getStrategyKey()))
		if(objTechInfo.getAdvisorType() != -1):
			szText = appendString(szText,"			<Advisor>%s</Advisor>" %(gc.getAdvisorInfo(objTechInfo.getAdvisorType()).getType()))
		else:
			szText = appendString(szText,"			<Advisor>NONE</Advisor>")
		szText = appendString(szText,"			<iAIWeight>%s</iAIWeight>" %(objTechInfo.getAIWeight()))
		szText = appendString(szText,"			<iAITradeModifier>%s</iAITradeModifier>" %(objTechInfo.getAITradeModifier()))
		szText = appendString(szText,"			<iCost>%s</iCost>" %(objTechInfo.getResearchCost()))
		if(objTechInfo.getEra() != -1):
			szText = appendString(szText,"			<Era>%s</Era>" %(gc.getEraInfo(objTechInfo.getEra()).getType()))
		else:
			szText = appendString(szText,"			<Era>NONE</Era>")
		
		if(objTechInfo.getFirstFreeUnitClass() != -1):
			szText = appendString(szText,"			<FirstFreeUnitClass>%s</FirstFreeUnitClass>" %(gc.getUnitClassInfo(objTechInfo.getFirstFreeUnitClass()).getType()))
		else:
			szText = appendString(szText,"			<FirstFreeUnitClass>NONE</FirstFreeUnitClass>")

		szText = appendString(szText,"			<iFeatureProductionModifier>%s</iFeatureProductionModifier>" %(objTechInfo.getFeatureProductionModifier()))
		szText = appendString(szText,"			<iWorkerSpeedModifier>%s</iWorkerSpeedModifier>" %(objTechInfo.getWorkerSpeedModifier()))
		szText = appendString(szText,"			<iTradeRoutes>%s</iTradeRoutes>" %(objTechInfo.getTradeRoutes()))
		szText = appendString(szText,"			<iHealth>%s</iHealth>" %(objTechInfo.getHealth()))
		szText = appendString(szText,"			<iHappiness>%s</iHappiness>" %(objTechInfo.getHappiness()))
		szText = appendString(szText,"			<iFirstFreeTechs>%s</iFirstFreeTechs>" %(objTechInfo.getFirstFreeTechs()))
		szText = appendString(szText,"			<iAsset>%s</iAsset>" %(objTechInfo.getAssetValue()))
		szText = appendString(szText,"			<iPower>%s</iPower>" %(objTechInfo.getPowerValue()))
		szText = appendString(szText,"			<bRepeat>%s</bRepeat>" %(boolToInt(objTechInfo.isRepeat())))
		szText = appendString(szText,"			<bTrade>%s</bTrade>" %(boolToInt(objTechInfo.isTrade())))
		szText = appendString(szText,"			<bDisable>%s</bDisable>" %(boolToInt(objTechInfo.isDisable())))
		szText = appendString(szText,"			<bGoodyTech>%s</bGoodyTech>" %(boolToInt(objTechInfo.isGoodyTech())))
		szText = appendString(szText,"			<bExtraWaterSeeFrom>%s</bExtraWaterSeeFrom>" %(boolToInt(objTechInfo.isExtraWaterSeeFrom())))
		szText = appendString(szText,"			<bMapCentering>%s</bMapCentering>" %(boolToInt(objTechInfo.isMapCentering())))
		szText = appendString(szText,"			<bMapVisible>%s</bMapVisible>" %(boolToInt(objTechInfo.isMapVisible())))
		szText = appendString(szText,"			<bMapTrading>%s</bMapTrading>" %(boolToInt(objTechInfo.isMapTrading())))
		szText = appendString(szText,"			<bTechTrading>%s</bTechTrading>" %(boolToInt(objTechInfo.isTechTrading())))
		szText = appendString(szText,"			<bGoldTrading>%s</bGoldTrading>" %(boolToInt(objTechInfo.isGoldTrading())))
		szText = appendString(szText,"			<bOpenBordersTrading>%s</bOpenBordersTrading>" %(boolToInt(objTechInfo.isOpenBordersTrading())))
		szText = appendString(szText,"			<bDefensivePactTrading>%s</bDefensivePactTrading>" %(boolToInt(objTechInfo.isDefensivePactTrading())))
		szText = appendString(szText,"			<bPermanentAllianceTrading>%s</bPermanentAllianceTrading>" %(boolToInt(objTechInfo.isPermanentAllianceTrading())))
		szText = appendString(szText,"			<bVassalTrading>%s</bVassalTrading>" %(boolToInt(objTechInfo.isVassalStateTrading())))		
		szText = appendString(szText,"			<bBridgeBuilding>%s</bBridgeBuilding>" %(boolToInt(objTechInfo.isBridgeBuilding())))
		szText = appendString(szText,"			<bIrrigation>%s</bIrrigation>" %(boolToInt(objTechInfo.isIrrigation())))
		szText = appendString(szText,"			<bIgnoreIrrigation>%s</bIgnoreIrrigation>" %(boolToInt(objTechInfo.isIgnoreIrrigation())))
		szText = appendString(szText,"			<bWaterWork>%s</bWaterWork>" %(boolToInt(objTechInfo.isWaterWork())))
		szText = appendString(szText,"			<iGridX>%s</iGridX>" %(objTechInfo.getGridX()))
		szText = appendString(szText,"			<iGridY>%s</iGridY>" %(objTechInfo.getGridY()))

		if(self.isDomainExtraMovesDefined(iTech)):
			szText = appendString(szText,"			<DomainExtraMoves>")
			for iI in range(DomainTypes.NUM_DOMAIN_TYPES):
				if(gc.getTechInfo(iTech).getDomainExtraMoves(iI) != 0):
					szText = appendString(szText,"				<DomainExtraMove>")
					szText = appendString(szText,"					<DomainType>%s</DomainType>" %(gc.getDomainInfo(iI).getType()))
					szText = appendString(szText,"					<iExtraMoves>%s</iExtraMoves>" %(gc.getTechInfo(iTech).getDomainExtraMoves(iI)))
					szText = appendString(szText,"				</DomainExtraMove>")
			szText = appendString(szText,"			</DomainExtraMoves>")
		else:
			szText = appendString(szText,"			<DomainExtraMoves/>")

		if(self.isCommerceFlexibleDefined(iTech)):
			szText = appendString(szText,"			<CommerceFlexible>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<bFlexible>%s</bFlexible>" %(boolToInt(gc.getTechInfo(iTech).isCommerceFlexible(iI))))
			szText = appendString(szText,"			</CommerceFlexible>")
		else:
			szText = appendString(szText,"			<CommerceFlexible/>")
		
		if(self.isTerrainTradeDefined(iTech)):
			szText = appendString(szText,"			<TerrainTrades>")
			for iI in range(gc.getNumTerrainInfos()):
				if(gc.getTechInfo(iTech).isTerrainTrade(iI)):
					szText = appendString(szText,"				<TerrainTrade>")
					szText = appendString(szText,"					<TerrainType>%s</TerrainType>" %(gc.getTerrainInfo(iI).getType()))
					szText = appendString(szText,"					<bTerrainTrade>1</bTerrainTrade>")
					szText = appendString(szText,"				</TerrainTrade>")
				
			szText = appendString(szText,"			</TerrainTrades>")
		else:
			szText = appendString(szText,"			<TerrainTrades/>")

		if(self.isFlavorsDefined(iTech)):
			szText = appendString(szText,"			<Flavors>")
			for iI in range(gc.getNumFlavorTypes()):
				if(gc.getTechInfo(iTech).getFlavorValue(iI) != 0):
					szText = appendString(szText,"				<Flavor>")
					szText = appendString(szText,"					<FlavorType>%s</FlavorType>" %(gc.getFlavorTypes(iI)))
					szText = appendString(szText,"					<iFlavor>%s</iFlavor>" %(gc.getTechInfo(iTech).getFlavorValue(iI)))
					szText = appendString(szText,"				</Flavor>")
			szText = appendString(szText,"			</Flavors>")
		else:
			szText = appendString(szText,"			<Flavors/>")
			
		if(self.isPrereqOrTechsDefined(iTech)):
			szText = appendString(szText,"			<OrPreReqs>")
			for iI in range (gc.getDefineINT("NUM_OR_TECH_PREREQS")):
				if(gc.getTechInfo(iTech).getPrereqOrTechs(iI) != TechTypes.NO_TECH):
					szText = appendString(szText,"				<PrereqTech>%s</PrereqTech>" %(gc.getTechInfo(gc.getTechInfo(iTech).getPrereqOrTechs(iI)).getType()))
			szText = appendString(szText,"			</OrPreReqs>")
		else:
			szText = appendString(szText,"			<OrPreReqs/>")
			
		if(self.isPrereqAndTechsDefined(iTech)):
			szText = appendString(szText,"			<AndPreReqs>")
			for iI in range (gc.getDefineINT("NUM_AND_TECH_PREREQS")):
				if(gc.getTechInfo(iTech).getPrereqAndTechs(iI) != TechTypes.NO_TECH):
					szText = appendString(szText,"				<PrereqTech>%s</PrereqTech>" %(gc.getTechInfo(gc.getTechInfo(iTech).getPrereqAndTechs(iI)).getType()))
			szText = appendString(szText,"			</AndPreReqs>")
		else:
			szText = appendString(szText,"			<AndPreReqs/>")
		
		szText = appendString(szText,"			<Quote>%s</Quote>" %(objTechInfo.getQuoteKey()))

		if(len(objTechInfo.getSound()) > 0):
			szText = appendString(szText,"			<Sound>%s</Sound>" %(objTechInfo.getSound()))
		else:
			szText = appendString(szText,"			<Sound/>")

		if(len(objTechInfo.getSoundMP()) > 0):
			szText = appendString(szText,"			<SoundMP>%s</SoundMP>" %(objTechInfo.getSoundMP()))
		else:
			szText = appendString(szText,"			<SoundMP/>")

		szText = appendString(szText,"			<Button>%s</Button>" %(objTechInfo.getButton()))

		szText = appendString(szText,"		</TechInfo>")

			
		return szText


	def printText(self, textList):
		strSavePath = ""
		strModPath = ""
		strModTextAssetPath = ""
		strModTextFilePath = ""
				
		if(os.access(CvPath.userActiveModDir,os.F_OK)):
			strModPath = CvPath.userActiveModDir
		elif(os.access(CvPath.installActiveModDir,os.F_OK)):
			strModPath = CvPath.installActiveModDir
		else:
			return
			
		strSavePath = "%s\%s" %(strModPath,g_strSaveDirectoryLocation)
		strModTextAssetPath = "%s\\Assets\\XML\\Text\\" %(strSavePath)
		strModTextFilePath = "%s\\CIV4GameTextInfo_%s.xml" %(strModTextAssetPath, g_strSaveDirectoryLocation)

		try:
			if(os.access(strModTextAssetPath,os.F_OK)):
				if(os.access(strModTextFilePath,os.F_OK)):
					os.remove(strModTextFilePath)
		except:
			pass
			
		if(not os.access(strModTextAssetPath,os.F_OK)):
			os.makedirs(strModTextAssetPath)
			
		szText = "<?xml version=\"1.0\"  encoding=\"ISO-8859-1\"?>"
		szText = appendString(szText,"<!-- Created by Tech Civilizeditor %s by TheLopez-->" %(editorVersion()))
		szText = appendString(szText,"<!-- edited with XMLSPY v2004 rel. 2 U (http://www.xmlspy.com) by XMLSPY 2004 Professional Ed. Release 2, Installed Multi + SMP for 3 users (Firaxis Games) -->")
		szText = appendString(szText,"<!-- Sid Meier's Civilization 4 -->")
		szText = appendString(szText,"<!-- Copyright Firaxis Games 2005 -->")
		szText = appendString(szText,"<!-- -->")
		szText = appendString(szText,"<!-- Game Text Objects -->")
		szText = appendString(szText,"<Civ4GameText xmlns=\"http://www.firaxis.com\">")

		for szTempText in textList:
			szText = appendString(szText,szTempText)
		
		szText = appendString(szText,"</Civ4GameText>")
		
		fd = os.open(strModTextFilePath, os.O_CREAT)
		os.close(fd)

		fd = os.open(strModTextFilePath, os.O_RDWR)
		os.write(fd, szText)
		os.close(fd)
		
		if(g_bSaveChangesInEditorAssetsDirectory):
			strModAssetPath = "%s\%s" %(strModPath,"\Assets\XML\Text")
			strModAssetSavePath = "%s\Assets\XML\Text\CIV4GameTextInfo_%s.xml" %(strModPath, g_strSaveDirectoryLocation)
			try:
				if(os.access(strModAssetPath,os.F_OK)):
					if(os.access(strModAssetSavePath,os.F_OK)):
						os.remove(strModAssetSavePath)
					os.removedirs(strModAssetPath)
			except:
				pass
				
			if(not os.access(strModAssetPath,os.F_OK)):
				os.makedirs(strModAssetPath)

			fd = os.open(strModAssetSavePath, os.O_CREAT)
			os.close(fd)

			fd = os.open(strModAssetSavePath, os.O_RDWR)
			os.write(fd, szText)
			os.close(fd)
						
	def printTechs(self):	
	
		strSavePath = ""
		strFileSavePath = ""
		strModPath = ""
		strModAssetPath = ""
		strModAssetSavePath = ""
		strModArtAssetPath = ""
		strModAssetPath = ""
		
		if(os.access(CvPath.userActiveModDir,os.F_OK)):
			strModPath = CvPath.userActiveModDir
		elif(os.access(CvPath.installActiveModDir,os.F_OK)):
			strModPath = CvPath.installActiveModDir
		else:
			self.dataSavePopup(false)
			return
			
		strSavePath = "%s\%s" %(strModPath,g_strSaveDirectoryLocation)
		strModArtAssetPath = "%s\\Assets\\Art\\Interface\\Buttons\\TechTree\\" %(strSavePath)
		strModAssetPath = "%s\\Assets\\" %(strModPath)
		
		if(g_bCreateAssetHierarchy):
			strSavePath += "\Assets\XML\Technologies" 

		strFileSavePath = "%s\%s" %(strSavePath, "CIV4TechInfos.xml")

		try:
			if(os.access(strSavePath,os.F_OK)):
				if(os.access(strFileSavePath,os.F_OK)):
					os.remove(strFileSavePath)
				os.removedirs(strSavePath)
		except:
			pass
			
		if(not os.access(strSavePath,os.F_OK)):
			os.makedirs(strSavePath)

							
		szText = "<?xml version=\"1.0\"?>"
		szText = appendString(szText,"<!-- Created by Tech Civilizeditor %s by TheLopez-->" %(editorVersion()))
		szText = appendString(szText,"<!-- Sid Meier's Civilization 4 -->")
		szText = appendString(szText,"<!-- Copyright Firaxis Games 2005 -->")
		szText = appendString(szText,"<!-- -->")
		szText = appendString(szText,"<!-- Tech Infos -->")
		szText = appendString(szText,"<Civ4TechInfos xmlns=\"x-schema:CIV4TechnologiesSchema.xml\">")
		szText = appendString(szText,"	<TechInfos>")
		

		techTextList = []
		
		for iTech in range(gc.getNumTechInfos()):

			if(gc.getTechInfo(iTech).isDeleted()):
				continue

			oldButtonPath = gc.getTechInfo(iTech).getButton()
			oldText = gc.getTechInfo(iTech).getTextKey()
			
			if(gc.getTechInfo(iTech).buttonChanged() and gc.getTechInfo(iTech).getButton() != None and gc.getTechInfo(iTech).getButton().find(",") == -1 and (os.path.exists(strModAssetPath+gc.getTechInfo(iTech).getButton()) or os.path.exists(gc.getTechInfo(iTech).getButton()))):
				if(not os.access(strModArtAssetPath,os.F_OK)):
					os.makedirs(strModArtAssetPath)

				filePath = gc.getTechInfo(iTech).getButton()
				
				if(not os.path.exists(gc.getTechInfo(iTech).getButton())):
					filePath = strModAssetPath+gc.getTechInfo(iTech).getButton()
				
				shutil.copy(filePath, strModArtAssetPath)
				
				gc.getTechInfo(iTech).setButton("Art/Interface/Buttons/TechTree/"+gc.getTechInfo(iTech).getButton().split("/")[len(gc.getTechInfo(iTech).getButton().split("/"))-1])
			
			if(oldText != "TXT_KEY_"+ gc.getTechInfo(iTech).getType()):
				gc.getTechInfo(iTech).setTextKey(str("TXT_KEY_"+ gc.getTechInfo(iTech).getType()))
				szDefText = "	<TEXT>\n		<Tag>TXT_KEY_%s</Tag>\n		<English>%s</English>\n		<French>%s</French>\n		<German>%s</German>\n		<Italian>%s</Italian>\n		<Spanish>%s</Spanish>\n	</TEXT>" %(gc.getTechInfo(iTech).getType(), oldText, oldText, oldText, oldText, oldText)
				techTextList.append(szDefText)
			szText = appendString(szText,self.printTech(iTech))
			
			gc.getTechInfo(iTech).setButton(oldButtonPath)
			
			if(oldText != "TXT_KEY_"+ gc.getTechInfo(iTech).getType()):
				gc.getTechInfo(iTech).setTextKey(str(oldText))
			
		szText = appendString(szText,"	</TechInfos>")
		szText = appendString(szText,"</Civ4TechInfos>")

		if(len(techTextList) > 0):
			self.printText(techTextList)
			
		fd = os.open(strFileSavePath, os.O_CREAT)
		os.close(fd)

		fd = os.open(strFileSavePath, os.O_RDWR)
		os.write(fd, szText)
		os.close(fd)
		
		if(g_bSaveChangesInEditorAssetsDirectory):
			strModAssetPath = "%s\%s" %(strModPath,"\Assets\XML\Technologies")
			strModAssetSavePath = "%s\%s" %(strModPath, "\Assets\XML\Technologies\CIV4TechInfos.xml")
			try:
				if(os.access(strModAssetPath,os.F_OK)):
					if(os.access(strModAssetSavePath,os.F_OK)):
						os.remove(strModAssetSavePath)
			except:
				pass
				
			if(not os.access(strModAssetPath,os.F_OK)):
				os.makedirs(strModAssetPath)

			fd = os.open(strModAssetSavePath, os.O_CREAT)
			os.close(fd)

			fd = os.open(strModAssetSavePath, os.O_RDWR)
			os.write(fd, szText)
			os.close(fd)
		
		if(gc.hasPromotionInfosChanged()):
			PromotionInfoWriter.PromotionInfoWriter().printPromotions()
		if(gc.hasCivicInfosChanged()):
			CivicInfoWriter.CivicInfoWriter().printCivics()
		if(gc.hasBuildingInfosChanged()):
			BuildingInfoWriter.BuildingInfoWriter().printBuildings()
		if(gc.hasSpecialBuildingInfosChanged()):
			SpecialBuildingInfoWriter.SpecialBuildingInfoWriter().printSpecialBuildings()
		if(gc.hasCivilizationInfosChanged()):
			CivilizationInfoWriter.CivilizationInfoWriter().printCivilizations()
		if(gc.hasHandicapInfosChanged()):
			HandicapInfoWriter.HandicapInfoWriter().printHandicaps()
		if(gc.hasBuildInfosChanged()):
			BuildInfoWriter.BuildInfoWriter().printBuilds()
		if(gc.hasRouteInfosChanged()):
			RouteInfoWriter.RouteInfoWriter().printRoutes()
		if(gc.hasImprovementInfosChanged()):
			ImprovementInfoWriter.ImprovementInfoWriter().printImprovements()
		if(gc.hasBonusInfosChanged()):
			BonusInfoWriter.BonusInfoWriter().printBonuss()
		if(gc.hasProcessInfosChanged()):
			ProcessInfoWriter.ProcessInfoWriter().printProcesss()
		if(gc.hasProjectInfosChanged()):
			ProjectInfoWriter.ProjectInfoWriter().printProjects()
		if(gc.hasReligionInfosChanged()):
			ReligionInfoWriter.ReligionInfoWriter().printReligions()
		if(gc.hasUnitInfosChanged()):
			UnitInfoWriter.UnitInfoWriter().printUnits()
		
		self.dataSavePopup(true)	


	def dataSavePopup(self, bSuccessful):
	
		strMessage = "Files saved successfully!!!"
		screen = CyGInterfaceScreen( "TechTreeEditor", CvScreenEnums.TECH_TREE_EDITOR )
		
		if(not bSuccessful):
			strMessage = "Files not saved!!!"
				
		popup = PyPopup.PyPopup()
		popup.setBodyString(strMessage)
		
		popup.setPosition((screen.getXResolution()/2)-200, (screen.getYResolution()/2)-75)
		popup.launch()
